package som.simon.reactor;

import reactor.core.publisher.Flux;

public class HandleMain implements CustomConstants {
    public static void main(String[] args) {

        // 自定义流中元素处理规则
        Flux<Object> flux = Flux.range(1, 10)
                .handle((ix, sink) -> {
                    // System.out.println("item = " + ix);
                    User user = getUserInfo(ix);

                    // 与map区别 这里可以每次返回不同类型的对象
                    sink.next(user);
                })
                .log();
        flux.subscribe();

    }

    private static User getUserInfo(Integer ix) {
        return User.builder()
                .id(String.format("%05d", ix))
                .name(NAMES[ix])
                // .password(UUID.randomUUID().toString())
                .desc(ix + "")
                .build();
    }

}
